<template>
    <div>
        <h1>科室信息显示</h1>
        <a href="/DepAdd">科室信息新增</a>
        <br>
        科室名称:
        <input type="text" v-model="Cha.DepName">
        创建时间
        <input type="date" v-model="Cha.BegTime">-<input type="date" v-model="Cha.EnvTime">
        <input type="button" value="查询" @click="Show">
        <input type="button" value="重置" @click="Chong">
        <table class="table">
            <thead>
                <tr>
                    <td>科室编号</td>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data">
                    <td>{{ a.DepId }}</td>
                    <td>{{a.DepName}}</td>
                    <td>{{a.DepNum}}</td>
                    <td>{{a.DepMiao}}</td>
                    <td>{{moment(a.DepDate).format("YYYY年MM月DD日")}}</td>
                    <td>
                        <input type="button" value="删除" @click="Del(a.DepId)">
                        <input type="button" value="修改" @click="Fan(a.DepId)">
                    </td>
                </tr>
            </tbody>
        </table>
         <a href="/DocShow">查看医生信息</a>
    </div>
</template>

<script setup lang="ts">

import { ref,onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter } from 'vue-router';
onMounted(()=>{
    Show();
})

const data = ref([{
    "DepId": 1,
    "DepName": "脑科",
    "DepNum": "120",
    "DepMiao": "术业有专攻",
    "DepDate": "2025-05-19T01:49:37.271",
    "DepIsDelete": true
}])


const Cha =ref({
    "DepName": "",
    BegTime:"",
    EnvTime:""
})
const Chong = ()=>{
    Cha.value.DepName="",
    Cha.value.BegTime="",
    Cha.value.EnvTime="",
    Show()
}
const Show=()=>{
    axios.get('https://localhost:7087/api/Depart/DepShow',{params:Cha.value}).then(res=>{
        data.value= res.data;
    })
}

//逻辑删除
const Del = (e:any)=>{
    if(confirm("确定删除吗？")){
        axios.delete('https://localhost:7087/api/Depart/DepDel',{params:{DepId:e}}).then(res=>{
            if(res.data>0){
                alert('删除成功')
                Show()
            }
            else{
                alert('删除失败');
            }
        })
    }
}
const router = useRouter()
//修改
const Fan=(e:any)=>{
    router.push({path:"/DepUpd",query:{DepId:e}});
}
</script>

<style scoped>

</style>